#include "Curses.h"
#include "Prompt.h"

//  /-------\
//  |Message|
//  |Yes  No|
//  \-------/
//
//


Prompt::Prompt(const std::string& message) 
 : Window(message.size() + 11, 4, 40 - ((message.size() + 11) / 2), 10, true), m_message(message)
{
	// ^^^ Automatically set width depending on message length, but need to 
	// count with Yes/No as well if message is shorter than them for
	// whatever reason.
}

bool Prompt::show() {
	Curses curses = Curses::instance();
	curses.pushWindow(this);
	
	curses.print(this, width() / 2 - (m_message.size() / 2), 1, m_message.c_str());
	curses.print(this, 1, 2, "Yes");
	curses.print(this, width() - 3, 2, "No");
	
	curses.refresh();
	
	int response = 0;
	while (response != 'y' && response != 'n') {
		response = curses.getchar();
		if (response == 'y' || response == 'n')
			break;
	}
	
	curses.popWindow();
	
	curses.clearScreen();
	curses.refresh();
	
	return (response == 'y') ? true : false;
}